/**
 * zmn权限模块-权限列表
 * 文件命名格式：zmn.模块名称.表名称.功能.js
 * @author heguanghua
 * @since 2020/04/23 11:50
 */
layui.define(['index', 'form', 'table', 'zmnApp', 'laypage', 'layedit', 'laydate'], function (exports) {
    let $ = layui.$;
    let form = layui.form;
    let layer = layui.layer;
    let table = layui.table;
    let laypage = layui.laypage;
    let layedit = layui.layedit;
    let laydate = layui.laydate;
    let zmnApp = layui.zmnApp;

    table.init('zmn-table', {
        toolbar: "#zmn-table-tool",
        page: true,
        limit: json.pageSize,
        height: 'full-140'
    });
    laypage.render(zmnPage.laypageOptions(json));

    // 启用/停用（批量）
    table.on("toolbar(zmn-table)", function (obj) {
        let ids = zmnPage.layTabldIds(obj, "permitId");
        if(obj.event != "start" && obj.event != "stop") { return; }
        if(ids.length === 0){ return layer.alert("请选择至少一个要操作的权限！"); }
        zmnPage.layStartStopBatch(obj, zmnApp.SYS_BASE_URL +"/permit/modify/modifyStatus.action", ids.join(","));
    });

    // 启用/停用（单个）
    form.on('switch(chk_status)', function(obj){
        zmnPage.layStartStop(obj, zmnApp.SYS_BASE_URL +"/permit/modify/modifyStatus.action");
    });

    // 修改排序
    table.on("edit(zmn-table)", function(obj){
        zmnPage.laySort(obj, zmnApp.SYS_BASE_URL +"/permit/modify/modifySort.action", obj.data.permitId);
    });

    layer.ready(function(){
        if(json.status){
            $("#status").val(json.status);
            form.render();
        }
    });

    //对外暴露的接口
    exports('permit_list', {});
});
